import { Component } from '@angular/core';
import { Storage } from '@ionic/storage';
import { IonicPage, ViewController, NavController, NavParams } from 'ionic-angular';
import { GlobalData } from '../../providers/GlobalData';

/**
 * Generated class for the SettingsPrintPage page.
 *
 * See http://ionicframework.com/docs/components/#navigation for more info
 * on Ionic pages and navigation.
 */
@IonicPage()
@Component({
  selector: 'page-settings-print',
  templateUrl: 'settings-print.html',
})
export class SettingsPrintPage {

  ipAddr: string;
  port: string;
  deviceId: string;

  constructor(public navCtrl: NavController,
    private storage: Storage,
    private global: GlobalData,
    private viewCtrl: ViewController,
    public navParams: NavParams) {
    this.storage.get('settings').then(setting => {
      this.ipAddr = setting.epson_ip_address;
      this.port = setting.epson_port;
      this.deviceId = setting.epson_device_id;
    });
  }

  changeIpAddr(ip) {
    console.log('changeIpAddr', ip);
    this.storage.get('settings').then(setting => {
      setting.epson_ip_address = ip;
      this.storage.set('settings', setting);
    });
  }

  changePort(port) {
    this.storage.get('settings').then(setting => {
      setting.epson_port = port;
      this.storage.set('settings', setting);
    });
  }

  changeDeviceId(deviceId) {
    this.storage.get('settings').then(setting => {
      setting.epson_device_id = deviceId;
      this.storage.set('settings', setting);
    });
  }

  changePrintBy(isPrintBy) {
    this.global.isPrintByDepartment = isPrintBy;
    this.storage.get('settings').then((setting) => {
      setting.is_print_by_department = isPrintBy;
      this.storage.set('settings', setting);
    });
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad SettingsPrintPage');
  }

  // dismiss table list modal
  dismiss() {
    this.viewCtrl.dismiss();
  }

}
